﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace calendar
{
    //例外日期类, 表示日历中的例外日期, 分工作例外和非工作例外. DayWorking(1/0)
    class CalendarException
    {

        private string m_name;                  //例外名称
        private int m_dayWorking;               //是否工作日
        private DateRange m_timePeriod;         //例外起始日期
        private ArrayList m_workingTimes;       //例外中工作时间段

        public CalendarException() {
            m_name = "null";
            m_dayWorking = 0;
            m_timePeriod = new DateRange();
            m_workingTimes = new ArrayList();
        }

        public string Name {
            get {
                return m_name;
            }
            set {
                m_name = value;
            }
        }

        public int DayWorking {
            get {
                return m_dayWorking;
            }
            set {
                m_dayWorking = value;
            }
        }

        public DateTime StartDate {
            get {
                return m_timePeriod.Start;
            }
            set {
                m_timePeriod.Start = value;
            }
        }

        public DateTime EndDate {
            get {
                return m_timePeriod.End;
            }
            set {
                if (value.TimeOfDay.Ticks == 0) { //如果时间是 00:00:00 , 则算到当天最后时间
                    m_timePeriod.End = value.AddTicks(TimeSpan.Parse("23:59:59").Ticks);
                } 
            }
        }

        public bool ContiainsDate(DateTime date)
        {
            if (date >= StartDate && date <= EndDate)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        public ArrayList WorkingTimes
        {
            get {
                return m_workingTimes;
            }
        }

        public ArrayList AddWorkingTime(DateRange daterange)
        {
            if (m_workingTimes.Contains(daterange) == false)
            {
                m_workingTimes.Add(daterange);
            }
            return m_workingTimes;
        }

        public ArrayList RemoveWorkingTime(DateRange daterange)
        {
            m_workingTimes.Remove(daterange);
            return m_workingTimes;
        }


    }
}
